#!/bin/bash
# 统计每个平台剩余未开区服数

script_path=/data/script/cqby-count
range_file=${script_path}/nameRange.ini
create_file=${script_path}/needCreatePlatform.ini
qufu_file=/data/.slogin.profile


getRange(){
    awk -v name=$1 '{if($1==name)print $3":"$4":"$6}' ${range_file}
}


getAllZhuCount(){
	#cd /data;./create_list_cqby
	for line in `cat ${create_file} | awk '{print $1}'`;do
		getOneZhuCount $line $1
	done
}

getOneZhuCount(){
	info=`getRange $1`
	if [ -z $info ];then
		echo "$1 平台不存在"
	else
	    platform=`echo $info | awk -F: '{print $1}'`
	    beginid=`echo $info | awk -F: '{print $2}'`
	    endid=`echo $info | awk -F: '{print $3}'`
	    endtime=$2
	    # echo $info
	    echo "$1:`awk -F, -v be=$beginid -v en=$endid -v platform=$platform  -v endtime=$endtime '{if($NF==1 && $1==platform && $2>=be && $2<=en && $5<=endtime)print $1,$2}' $qufu_file | wc -l`"
	fi
}

case $# in
2)
    cd /data;./create_list_cqby
    [ $1 == "all" ] && getAllZhuCount $2 || getOneZhuCount $1 $2
    ;;
*)
    echo "usage:`basename $0` 平台名称/all"
    ;;
esac